using HtmlAgilityPack;

namespace StaffWars.Services
{
    public class ScreenScrapingService
    {
        public HtmlNode GetElementByID(string url, string id)
        {
            return GetElementByXPath(url, string.Format("//div[@id='{0}']", id));
        }

        public HtmlNode GetElementByClass(string url, string @class)
        {
            return GetElementByXPath(url, string.Format("//div[@class='{0}']", @class));
        }

        public HtmlNode GetElementByClass(string url, string element, string @class)
        {
            return GetElementByXPath(url, string.Format("//{0}[@class='{1}']", element, @class));
        }

        public HtmlNode GetElementByXPath(string url, string xpath)
        {
            var hw = new HtmlWeb();
            var htmlDoc = hw.Load(url);

            return htmlDoc.DocumentNode.SelectSingleNode(xpath);
        }
    }
}
